<?php

namespace app\common\order\validate;


use app\common\product\logic\StoreCategoryLogic;
use think\Validate;

class OrderProtocolValidate extends Validate
{
    protected $rule = [
        'company_id' => ['require'],
        'category_id' => ['require'],
        'price' => ['require'],
        'amount' => ['require'],
    ];

    protected $message = [
        'company_id.require' => '请选择承办公司',
        'category_id.require' => 'category_id参数错误',
        'price.require' => '请录入餐标',
        'amount.require' => '请录入桌数',
    ];

    protected function checkBanquet($value, $rule, $data)
    {
        $categoryLogic = new StoreCategoryLogic();
        $category = $categoryLogic->getStoreCategory($data['category_id']);
        if ($category['order_model'] == 'Banquet') {
            if ($value > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    protected function checkProduct($value, $rule, $data)
    {
        $categoryLogic = new StoreCategoryLogic();
        $category = $categoryLogic->getStoreCategory($data['category_id']);
        if ($category['order_model'] == 'Wedding') {
            if ($value > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    protected function checkPrice($value, $rule, $data)
    {
        $categoryLogic = new StoreCategoryLogic();
        $category = $categoryLogic->getStoreCategory($data['category_id']);
        if ($category['order_model'] == 'Banquet' || $category['order_model'] == 'Baby') {
            if ($value > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    protected function checkAmount($value, $rule, $data)
    {
        $categoryLogic = new StoreCategoryLogic();
        $category = $categoryLogic->getStoreCategory($data['category_id']);
        if ($category['order_model'] == 'Banquet' || $category['order_model'] == 'Baby') {
            if ($value > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

}